//
//  UIView+Shadow.m
//  Arts1
//
//  Created by apple on 15/8/29.
//  Copyright (c) 2015年 Arts1. All rights reserved.
//

#import "UIView+Shadow.h"
#import "AllHeader.h"

@implementation UIView (Shadow)

+ (void)viewShadowColor:(UIView *)view
{
    //加阴影--任海丽编辑
    view.layer.shadowColor = [UIColor blackColor].CGColor;//shadowColor阴影颜色
    view.layer.shadowOffset = CGSizeMake(0,0.1);//shadowOffset阴影偏移,x向右偏移4，y向下偏移4，默认(0, -3),这个跟shadowRadius配合使用
    view.layer.shadowOpacity = 0.5;//阴影透明度，默认0
    view.layer.shadowRadius = 0.1;//阴影半径，默认3
}

// 设置阴影为宽阴影
+ (void)viewWideForShadowColor:(UIView *)view{
    view.layer.shadowColor = [UIColor blackColor].CGColor;
    [view.layer setShadowOffset:(CGSizeMake(0, 0.5))];
    view.layer.shadowRadius = 1;
    [view.layer setShadowOpacity:0.5];
}

// 设置左侧两个角为圆角
+ (void)viewRediusForTopAndBottomForLeft:(UIView *)view withRedius:(NSInteger)r{
    UIBezierPath *maskPath=  [UIBezierPath bezierPathWithRoundedRect:view.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerTopLeft cornerRadii:CGSizeMake(r, r)];
    CAShapeLayer *maskLayer=[[CAShapeLayer alloc] init];
    maskLayer.frame = view.bounds;
    maskLayer.path=maskPath.CGPath;
    view.layer.mask=maskLayer;
    view.layer.masksToBounds=YES;
}

// 设置底部两个角为圆角
+ (void)viewRediusForLeftAndReightOfBottom:(UIView *)view withRedius:(NSInteger)r{
    UIBezierPath *maskPath=  [UIBezierPath bezierPathWithRoundedRect:view.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(r, r)];
    CAShapeLayer *maskLayer=[[CAShapeLayer alloc] init];
    maskLayer.frame = view.bounds;
    maskLayer.path=maskPath.CGPath;
    view.layer.mask=maskLayer;
    view.layer.masksToBounds=YES;
}

// 设置头部两个角为圆角
+ (void)viewRediusForLeftAndReightOfTop:(UIView *)view withRedius:(NSInteger)r{
    UIBezierPath *maskPath=  [UIBezierPath bezierPathWithRoundedRect:view.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(r, r)];
    CAShapeLayer *maskLayer=[[CAShapeLayer alloc] init];
    maskLayer.frame = view.bounds;
    maskLayer.path=maskPath.CGPath;
    view.layer.mask=maskLayer;
    view.layer.masksToBounds=YES;
}

// 给视图添加模糊效果
+ (void)viewOfBlurEffect:(UIView *)view withAlpha:(CGFloat)alpha{

    UIVisualEffect *lightBlurEffect = [UIBlurEffect effectWithStyle:(UIBlurEffectStyleLight)];
    UIVisualEffectView *visualEffectView = [[UIVisualEffectView alloc] initWithEffect:lightBlurEffect];
    visualEffectView.frame = view.bounds;
    visualEffectView.alpha = alpha;
    [view addSubview:visualEffectView];
}

+ (UIImage *)imageFromView: (UIView *) theView
{
    
    UIGraphicsBeginImageContext(theView.frame.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    [theView.layer renderInContext:context];
    UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return theImage;
}

- (UIImage *) screenShotFromView:(UIView *)view {
    UIGraphicsBeginImageContext(view.bounds.size);
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];
    
    UIImage *image= UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    NSLog(@"image:%@",image);
    
//    UIImageView *imaView = [[UIImageView alloc] initWithImage:image];
//    imaView.frame = CGRectMake(0, 700, 500, 500);
//    [view addSubview:imaView];
    
//    UIImageWriteToSavedPhotosAlbum(image, self, nil, nil);
    return image;
}


@end
